<?php
class SysAccountsForm extends BaseFormAdmin{
	public function configure(){
		$group_id_query = Doctrine_Query::create()
			->from('SysAccountGroups al')
			->select('al.id, al.name as name')
			->where('al.is_enabled = 1 AND al.is_deleted = 0')
			->andWhere('(al.updated_at IS NULL OR al.updated_at >= al.created_at)')
			->andWhere('al.name <> ?', 'root')
			->andWhere('al.type <> ?', 2)
			->orderBy('al.name asc');
			
		
		$this->setWidget('group_id',new sfWidgetFormDoctrineChoice(array(
				'model' 		=> 'SysAccountGroups',
				'query'			=> $group_id_query,
				'multiple' 		=> false,
				'add_empty' 	=> __('select-option-all')), array('class' =>'required hz-required')
		));
		$this->setValidator('group_id', new sfValidatorDoctrineChoice(array(
				'model' => 'SysAccountGroups',
				'query' => $group_id_query,
				'required' => true), array('required'=> 'error-select')
		));
		$this->setDefault('group_id', '-1');
		
		$this->setWidget('name', new sfWidgetFormInputText(array(), array('class' => 'required hz-required')));
		$this->setValidator('name', new sfValidatorString(array('max_length' => 255, 'required' => true)));
		
		$this->setWidget('login_user', new sfWidgetFormInputText(array(), array('class' => 'required hz-required')));
		$this->setValidator('login_user', new sfValidatorString(array('max_length' => 255, 'required' => true)));
		
		$this->setWidget('login_password', new sfWidgetFormInputPassword(array(), array('class' => 'required hz-required password hz-confirm-required', 'data-id-confirm' => 'AdminFForm_password_confirm')));
		$this->setValidator('login_password', new sfValidatorString(array('max_length'=> 255, 'required' => false)));
		
		$this->setWidget('password_confirm', new sfWidgetFormInputPassword(array(), array('class' => 'required password')));
		$this->setValidator('password_confirm', new sfValidatorString(array('max_length'=> 255, 'required' => false)));
		
		
		$this->setWidget('email', new sfWidgetFormInputText(array(), array('class' => 'required hz-required hz-email')));
		$this->setValidator('email', new sfValidatorAnd(array(new sfValidatorString(array('max_length'=> 255)),
				new sfValidatorEmail(array(), array('invalid' => __('error_email_invalid')))
		)));
		
		parent::configure();
	}
}
